package com.ruicar.afs.cloud.channel.event;

import com.ruicar.afs.cloud.admin.api.dto.UserSimpleInfoDto;
import com.ruicar.afs.cloud.admin.api.event.AfsOnUserChange;
import com.ruicar.afs.cloud.admin.api.event.UserChangeEventParam;
import com.ruicar.afs.cloud.channel.mange.entity.ChannelUser;
import com.ruicar.afs.cloud.channel.mange.service.ChannelUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Ice
 */
@Component
@Slf4j
@AllArgsConstructor
@Service
public class AfsOnUserChangeEvent implements AfsOnUserChange {
    private final ChannelUserService userService;
    @Override
    public boolean onRoleChange(UserChangeEventParam userChangeEventParam) {
        //  主要是接收更新用户的真实姓名
        List<UserSimpleInfoDto> list =userChangeEventParam.getUserSimpleInfoLists();
        List<ChannelUser> user=userService.list();
        if(list.size()>0&&user.size()>0){
            for (int i=0;i<list.size();i++){
                for (int j=0;j<user.size();j++){
                    if(list.get(i).getUserId()==user.get(j).getUserId()){
                        user.get(j).setUsername(list.get(i).getUserName());
                        user.get(j).setUserRealName(list.get(i).getUserRealName());
                        userService.updateById(user.get(j));
                    }
                }
            }
        }

        return true;
    }
}
